//@author A0084731E

import java.util.Comparator;

// Sort payment method by lexicographical order
class PaymentMethodComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2){
		return t1.getPaymentMethod().compareToIgnoreCase(t2.getPaymentMethod());
	}
}

// Sort category by lexicographical order
class CategoryComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2){
		return t1.getCategory().compareToIgnoreCase(t2.getCategory());
	}
}

// Sort date
class DateComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2){
		return t2.getDate().compareTo(t1.getDate());
	}
}

// Sort label in lexicographical order
class NameComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2) {
		return t1.getName().compareToIgnoreCase(t2.getName());
	}
}

// Sort by priority value, largest to smallest
class PriorityComparator implements Comparator<Transaction>{
	public int compare(Transaction itemX1, Transaction itemX2){
		BudgetPlannerItem item1 = null;
		BudgetPlannerItem item2 = null;
		if(itemX1 instanceof BudgetPlannerItem && itemX2 instanceof BudgetPlannerItem) {
			item1 = (BudgetPlannerItem) itemX1;
			item2 = (BudgetPlannerItem) itemX2;
		}
		if(item1.getPriority()!=item2.getPriority())//diff priority
			return item2.getPriority()-item1.getPriority();

		else{//same priority, compare value
			if((item1.getValue()-item2.getValue())<=0)
				return -1;
			else
				return 1;
		}
	}
}

// Sort remarks in lexicographical order
class RemarksComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2){
		return t1.getRemarks().compareToIgnoreCase(t2.getRemarks());
	}
}

// Sort status, OUTSTANDING first , followed by PAID
class StatusComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2){
		if(t1.getStatus().equals(t2.getStatus()))
			return 0;
		if(t1.getStatus().equals(TransactionStatus.OUTSTANDING))
			return -1;
		else
			return 1;
	}
}

// Sort type, DEPOSIT first, followed by EXPENSE
class TypeComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2){
		if(t1.getType().equals(t2.getType()))
			return 0;
		if(t1.getType().equals(TransactionType.DEPOSIT))
			return -1;
		else
			return 1;

	}
}

// Sort by value, smallest to largest
class ValueComparator implements Comparator<Transaction>{
	public int compare(Transaction t1, Transaction t2){
		if((t1.getValue()-t2.getValue())<=0)
			return -1;
		else
			return 1;
	}
}

// Sort by ID, smallest to largest
class IDComparator implements Comparator<Transaction> {
	public int compare(Transaction t1, Transaction t2){
		if((t1.getID()-t2.getID())<=0)
			return -1;
		else
			return 1;
	}
}